package com.piece.core.framework.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 权限级别页面展示
 */
@Getter
@AllArgsConstructor
public enum PermLevelType {

    /**
     * 只读权限
     */
    Level_ReadOnly("readonly", null),
    /**
     * 禁用权限
     */
    Level_Disable("disabled", null),
    /**
     * 权限级别标识
     */
    Level_1("acl_level_1", 1),
    Level_2("acl_level_2", 2),
    Level_3("acl_level_3", 3),
    Level_4("acl_level_4", 4),
    Level_5("acl_level_5", 5),
    /**
     * 无限制
     */
    None("none", 999);

    private String name;
    private Integer level;

    public Integer getLevel(String name) {
        PermLevelType type = PermLevelType.valueOf(name);
        return null == type ? null : type.level;
    }

    public int compare(String name_1, String name_2) {
        PermLevelType type_1 = PermLevelType.valueOf(name_1);
        PermLevelType type_2 = PermLevelType.valueOf(name_2);

        if (null == type_1 || null == type_2) {
            return 0;
        }

        return type_1.level > type_2.level ? 1 : (type_1.level < type_2.level ? -1 : 0);
    }
}